package com.study.system.controller;

import com.study.common.result.Result;
import com.study.model.system.SysDept;
import com.study.system.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "Department")
@RestController
@RequestMapping("/admin/system/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @ApiOperation(value = "find all")
    @GetMapping("all")
    public Result findAll(){
        List<SysDept> tree = sysDeptService.findNodes();
        return Result.ok(tree);
    }

    @ApiOperation(value = "delete")
    @GetMapping("delete/{id}")
    public Result deleteById(@PathVariable Long id){
        sysDeptService.deleteById(id);
        return Result.ok();
    }

    @ApiOperation(value = "添加")
    @PostMapping("insert")
    public Result insert(@RequestBody SysDept sysDept){
        sysDeptService.save(sysDept);
        return Result.ok();
    }

    @ApiOperation(value = "修改")
    @PostMapping("update")
    public Result update(@RequestBody SysDept sysDept){
        sysDeptService.updateById(sysDept);
        return Result.ok();
    }
}
